package com.aidex.biz.controller;

import java.io.IOException;
import java.util.List;

import com.aidex.biz.domain.PersonInfo;
import com.aidex.common.annotation.Log;
import com.aidex.common.core.domain.AjaxResult;
import com.aidex.common.core.domain.R;
import com.aidex.common.core.domain.model.LoginUser;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.page.PageDomain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.aidex.common.enums.BusinessType;
import com.aidex.common.utils.poi.ExcelUtil;
import javax.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import com.aidex.common.core.controller.BaseController;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import com.aidex.biz.domain.ZhuanxiangAssess;
import com.aidex.biz.service.ZhuanxiangAssessService;
import com.aidex.common.utils.SecurityUtils;
import org.springframework.web.multipart.MultipartFile;

/**
 * 专项监督Controller
 * @author sean
 * @email 2074844820@qq.com
 * @date 2025-03-26
 */
@RestController
@RequestMapping("/biz/bizZhuanxiangAssess")
public class ZhuanxiangAssessController extends BaseController
{
    @Autowired
    private ZhuanxiangAssessService zhuanxiangAssessService;

    /**
     * 查询专项监督列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:list')")
    @GetMapping("/list")
    public R<PageInfo> list(ZhuanxiangAssess zhuanxiangAssess, HttpServletRequest request, HttpServletResponse response)
    {
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                zhuanxiangAssess.setCompanyId(null);
        }else{
                     zhuanxiangAssess.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                 }
        zhuanxiangAssess.setPage(new PageDomain(request, response));
        return R.data(zhuanxiangAssessService.findPage(zhuanxiangAssess));
    }

    /**
     * 获取专项监督详细信息
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:query')")
    @GetMapping(value = "/{id}")
    public R<ZhuanxiangAssess> detail(@PathVariable("id") String id)
    {
        return R.data(zhuanxiangAssessService.get(id));
    }

    /**
     * 新增专项监督
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:add')")
    @Log(title = "专项监督", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody @Validated  ZhuanxiangAssess zhuanxiangAssess)
    {
        return R.status(zhuanxiangAssessService.save(zhuanxiangAssess));
    }

    /**
     * 修改专项监督
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:edit')")
    @Log(title = "专项监督", businessType = BusinessType.UPDATE)
    @PutMapping
    public R edit(@RequestBody @Validated ZhuanxiangAssess zhuanxiangAssess)
    {
        return R.status(zhuanxiangAssessService.save(zhuanxiangAssess));
    }


    /**
     * 删除专项监督
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:remove')")
    @Log(title = "专项监督", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R remove(@PathVariable String[] ids)
    {
        return R.status(zhuanxiangAssessService.deleteZhuanxiangAssessByIds(ids));
    }

    /**
     * 获取最大编号
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:query')")
    @GetMapping("/findMaxSort")
    public R findMaxSort()
    {
        return R.data(zhuanxiangAssessService.findMaxSort(new ZhuanxiangAssess()));
    }

    /**
     * 导出专项监督列表
     */
    @PreAuthorize("@ss.hasPermi('biz:bizZhuanxiangAssess:export')")
    @Log(title = "专项监督", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public R export(ZhuanxiangAssess zhuanxiangAssess)
    {

            if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
                    zhuanxiangAssess.setCompanyId(null);
            }else{
                         zhuanxiangAssess.setCompanyId(SecurityUtils.getLoginUser().getUser().getCompanyId());
                     }
        List<ZhuanxiangAssess> list = zhuanxiangAssessService.findList(zhuanxiangAssess);
        ExcelUtil<ZhuanxiangAssess> util = new ExcelUtil<ZhuanxiangAssess>(ZhuanxiangAssess.class);
        return util.exportExcel(list, "专项监督数据");
    }

    /**
     * 导入专项监督列表
     */
    @Log(title = "专项监督", businessType = BusinessType.EXPORT)
    @PostMapping("/importInfo")
    public AjaxResult importInfo(MultipartFile file, boolean updateSupport) throws Exception {
        ExcelUtil<ZhuanxiangAssess> util = new ExcelUtil<ZhuanxiangAssess>(ZhuanxiangAssess.class);
        List<ZhuanxiangAssess> zhuanxiangAssessList = util.importExcel(file.getInputStream());
        String message = zhuanxiangAssessService.importInfo(zhuanxiangAssessList);
        return AjaxResult.success(message);
    }

}
